package com.gaohe.controller;

import com.gaohe.pojo.Book;
import com.gaohe.service.BookService;
import com.gaohe.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RequestMapping("/books")
@RestController
public class BookController {
    @Autowired
    private BookService service;

    /**
     * 查看全部
     * @return
     */
    @GetMapping
    public Result listBooks() {
        System.out.println("listBooks");
        return service.listBooks();
    }

    /**
     * 新增
     * @param book
     * @return
     */
    @PostMapping
    public Result saveBook(@RequestBody Book book){
        return service.savaBook(book);
    }

    /**
     * 根据id删除
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public String deleteById(@PathVariable Integer id){
        return service.deleteById(id);
    }

    /**
     * 多条件查询
     * @param book
     * @return
     */
    @PostMapping("/getByConditions")
    public List<Book> getByConditions(@RequestBody Book book){
        return service.getByConditions(book);
    }

    /**
     * 修改
     * @param book
     * @return
     */
    @PutMapping
    public String updateById(@RequestBody Book book){
        return service.updateById(book);
    }


}
